<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<h3 class="sub-header">博客管理</h3>
				<button class="btn btn-primary" data-toggle="modal" data-target="#addBlogDiv">添加</button>
				<div class="table-responsive">
					<table class="table">
						<thead>
							<tr>
								<th>编号</th>
								<th>博客名</th>
								<th>描述</th>
								<th>背景图</th>
								<th>发布时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${blogPage.list }" var="blog" varStatus="v">
								<tr class="active">
									<td>${v.count }</td>
									<td>${blog.name }</td>
									<td>${fn:substring(blog.description,0,20) }</td>
									<td>${blog.bgImage }</td>
									<td>${blog.createTime }</td>
									<td>
										<button type="button"
											class="btn btn-default btn-xs  btn-warning" onclick="getBlog(${blog.id})" data-toggle="modal" data-target="#updateDialog">修改</button> 
											<a href="${ctx }/blog/delete?id=${blog.id}" class="btn btn-default btn-xs  btn-danger">删除</a>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<ul class="pagination">
						<li><a
							href="<%=request.getContextPath() %>/blog/list.action?pageNo=${blogs.pre}">&laquo;</a></li>
						<li class="active"><a
							href="<%=request.getContextPath()%>/blog/list.action?pageNo=1">1</a></li>
						<li><a
							href="<%=request.getContextPath()%>/blog/list.action?pageNo=2">2</a></li>
						<li><a
							href="<%=request.getContextPath()%>/blog/list.action?pageNo=3">3</a></li>
						<li><a
							href="<%=request.getContextPath()%>/blog/list.action?pageNo=4">4</a></li>
						<li><a
							href="<%=request.getContextPath()%>/blog/list.action?pageNo=5">5</a></li>
						<li><a
							href="<%=request.getContextPath() %>/blog/list.action?pageNo=${blogs.next}">&raquo;</a></li>
					</ul>
				</div>

 		<!-- 新增界面 -->
	    <div class="modal fade" id="addBlogDiv" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		  <div class="modal-dialog">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
		        <h4 class="modal-title" id="myModalLabel">新增博客</h4>
		      </div>
		      <div class="modal-body">
				<form class="form-horizontal" role="form" action="<%=request.getContextPath() %>/blog/add" method="post">
				<input type="hidden" name="userId" value="${user.id }"/>
				  <div class="form-group">
				    <label for="name" class="col-sm-2 control-label">name</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" name="name">
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="description" class="col-sm-2 control-label">description</label>
				    <div class="col-sm-10">
				      <textarea  class="form-control" name="description" ></textarea>
				    </div>
				  </div>
				  <div class="form-group">
				    <label for="bgImage" class="col-sm-2 control-label">bgImage</label>
				    <div class="col-sm-10">
				      <input type="text" class="form-control" name="bgImage">
				    </div>
				  </div>
			
				  <div class="form-group">
				    <div class="col-sm-offset-2 col-sm-10">
				      <button type="submit" class="btn btn-primary">新增</button>
				    </div>
				  </div>
				</form>
		      </div>
		    </div>
		  </div>
		</div>
	<div class="modal fade" id="updateDialog" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content loginbox">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
					</button>
					<h4 class="modal-title">修改</h4>
				</div>
				<form class="form-signin" role="form" action="<%=request.getContextPath() %>/blog/updateBlog.action" method="post">
				<input type="hidden" name="id" id="update_id">
				<input type="hidden" name="bgImage" id="update_bgImage">
				<input type="hidden" name="userId" id="update_userId">
					文章标题： <input id="update_name" name="name" class="form-control" placeholder="文章标题"
						required autofocus> 文章内容:
					<textarea id="update_description" name="description" class="form-control" placeholder="文章内容" required></textarea>
					<input class="btn btn-lg btn-primary btn-block" type="submit" value="修改" ></input>
				</form>
			</div>
		</div>
	</div>
	<script>
	getBlog = function(id){
		$.post("<%=request.getContextPath() %>/blog/get",{'id':id},function(data){
			$("#update_name").val(data.name);
			$("#update_description").html(data.description);
			$("#update_id").val(data.id);
			$("#update_bgImage").val(data.bgImage);
			$("#update_userId").val(data.userId);
		},'json');
	};
	
	
	</script>
				